package cn.web.web_module.updateweb;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author: 张松
 * @Description:
 * @Date: Created in 18:26 2020/7/18
 * @Modified By:
 */
public class EveryDayDataExcel {

    public static HSSFWorkbook getHssfWorkbook(String sheetName, String []title, Map<String,Object> map, HSSFWorkbook wb){
        //第一步创建HSSFWorkbook,对应一个Excel文件
        if (wb==null){
            wb= new HSSFWorkbook();
        }
        //第二步 在workbook中添加一个sheet,对应excel中的sheet
        HSSFSheet sheet = wb.createSheet(sheetName);

        //第三步 在sheet中添加表头第0行
        HSSFRow row = sheet.createRow(0);

        //第四步,创建单元格,并设置表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);

        //声明列对象
        HSSFCell cell = null;

        //创建标题
        for (int i=0;i<title.length;i++){
            cell = row.createCell(i);
            cell.setCellValue(title[i]);
            cell.setCellStyle(style);
        }

        int i=0;
        //创建文本内容
        for (String key:map.keySet()){
            Map<String,Object> tempMap=(Map<String,Object>)map.get(key);
            row = sheet.createRow( i+1);
                row.createCell(0).setCellValue(key);
                row.createCell(1).setCellValue((Integer)tempMap.get("AllAddUser"));
                row.createCell(2).setCellValue((Integer)tempMap.get("allUserCount"));
                row.createCell(3).setCellValue((Integer)tempMap.get("countOrder"));
                row.createCell(4).setCellValue((Integer)tempMap.get("completedOrder"));
                row.createCell(5).setCellValue((Integer)tempMap.get("incompleteOrder"));
                row.createCell(6).setCellValue((Integer)tempMap.get("excepOrder"));
                row.createCell(7).setCellValue(tempMap.get("allWeight").toString());
                row.createCell(8).setCellValue(tempMap.get("allMoney").toString());
            i++;
        }

        return wb;
    }
}
